package com.frank.game.rule;

import com.frank.game.base.Area;
import com.frank.game.base.World;
import com.frank.game.base.unit.Unit;
import com.frank.game.derivative.Filler;
import com.frank.game.derivative.Plant;

/**
 * @deprecated:创建规则
 * @author frank
 * @date 2015年12月15日
 */
public class CreateRule {
	
	private World world;
	
	public static CreateRule newCreateRule() {
		return new CreateRule();
	}
	
	private CreateRule() {
		createWorld();
	}
	
	private void createWorld(){
		world = new World();
		infoAreas();
	}
	
	private void infoAreas(){
		Area[][][] areas = world.getAreas();
		for (int x = 0; x < world.getLength(); x++) {
			for (int y = 0; y < world.getWidth(); y++) {
				for (int z = 0; z < world.getHeight(); z++) {
					areas[x][y][z] = new Area(getAreaType(x, y, z));
				}
			}
		}
	}
	
	public static Unit getUnit(int x, int y, int z, Area area) {
		switch (area.getType()) {
		case air:
			return new Filler(x, y, z, Filler.FillerType.air);
		case plain:
			if(z < area.getHeight()/2){
				return new Filler(x, y, z, Filler.FillerType.soil);
			}
			if(z == area.getHeight()/2){
				return new Plant(x, y, z);
			}
			return new Filler(x, y, z, Filler.FillerType.air);
		case forest:
			if(z < area.getHeight()/2){
				return new Filler(x, y, z, Filler.FillerType.soil);
			}
			return new Filler(x, y, z, Filler.FillerType.air);
		case hill:
			if(z < area.getHeight()/2){
				return new Filler(x, y, z, Filler.FillerType.soil);
			}
			return new Filler(x, y, z, Filler.FillerType.air);
		case mountain:
			if(z < area.getHeight()/2){
				return new Filler(x, y, z, Filler.FillerType.soil);
			}
			return new Filler(x, y, z, Filler.FillerType.air);
		case burrow:
			return new Filler(x, y, z, Filler.FillerType.soil);
		case cave:
			return new Filler(x, y, z, Filler.FillerType.soil);
		default:
			return new Filler(x, y, z, Filler.FillerType.air);
		}
	}
	
	private Unit getUnit(Plant plant) {
		
		return plant;
	}
	
	public World getWorld(){
		return world;
	}
	//通过x、y、z获取地形
	private Area.AreaType getAreaType(int x, int y, int z){
		if(z < this.world.getHeight()/2) {	
			return Area.AreaType.burrow;
		}
		if(z == this.world.getHeight()/2) {	
			
			return Area.AreaType.plain;
		}
		
		return Area.AreaType.air;
	}
	
}
